package com.hhkj.study.api.user.controller;

import com.hhkj.study.api.user.common.manager.AccountLoginManager;
import com.hhkj.study.api.user.model.req.*;
import com.hhkj.study.api.user.sevice.biz.ApiCustomerUserBizService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.login.api.ApiLoginOpen;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author luowu
 * @Date 2024/9/26 涵 14:20:24
 */
@RestController
@RequestMapping("/api/user")
public class ApiCustomerUseController {

    @Resource
    private ApiCustomerUserBizService customerUserBizService;

    @Resource
    private AccountLoginManager accountLoginManager;

    /** 登录 */
    @ApiLoginOpen
    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody ApiCustomerUserLoginReq req) {
        return AjaxResult.success(customerUserBizService.login(req));
    }

    /** 退出登录 */
    @PostMapping("/logout")
    public AjaxResult logout() {
        accountLoginManager.logout();
        return AjaxResult.success();
    }

    /**
     * 暂时不用
     * 微信登录/注册(包括微信扫码,小程序端登录)
     * @param req
     * @return
     */
    @ApiLoginOpen
    @PostMapping("/wx/login")
    public AjaxResult wxLogin(@Validated @RequestBody ApiCustomerUserWxLoginReq req) {
        return AjaxResult.success(customerUserBizService.wxLogin(req));
    }


    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/info")
    public AjaxResult getInfo() {
        return AjaxResult.success(customerUserBizService.getInfo());
    }


    /**
     * 个人资料修改
     * @return
     */
    @PutMapping
    public AjaxResult update(@Validated @RequestBody ApiCustomerUserUpdateReq req) {
        return AjaxResult.success(customerUserBizService.update(req));
    }

    /**
     * 验证手机号
     * @return
     */
    @PostMapping("/verify/mobile")
    public AjaxResult verifyMobile(@Validated @RequestBody ApiCustomerUserBaseReq req) {
        return AjaxResult.success(customerUserBizService.verifyMobile(req));
    }

    /**
     * 修改密码
     * @return
     */
    @PutMapping("/pwd")
    public AjaxResult updatePwd(@Validated @RequestBody ApiCustomerUserPwdUpdateReq req) {
        return AjaxResult.success(customerUserBizService.updatePwd(req));
    }

}
